class StorageManger {
	get<T>(key: string, storage: Storage = window.localStorage) {
		let data = storage.getItem(key);
		if (data) {
			let json = JSON.parse(data);
			return json as T;
		}
		return undefined;
	}

	set<T = any>(key: string, value: T, storage: Storage = window.localStorage) {
		let json = JSON.stringify(value);
		storage.setItem(key, json);
	}

	remove(key: string, storage: Storage = window.localStorage) {
		storage.removeItem(key);
	}

	clear(storage: Storage = window.localStorage) {
		storage.clear();
	}
}

export default new StorageManger();
